package org.adapter;

import java.util.List;

import org.cmn.MerchantPojo;
import org.cmn.SalePojo;
import org.design.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SaleAdapter extends GenericAdapter {
	public SaleAdapter(Context context, List<SalePojo> listSales) {
		super(context, listSales);
	}

	public int getCount() {
		return getResulstList().size();
	}

	public Object getItem(int position) {
		return getResulstList().get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup viewGroup) {
		SalePojo entry = (SalePojo) getResulstList().get(position);
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.order_sale_row, null);
		}
		TextView productName = (TextView) convertView
				.findViewById(R.id.productName);
		productName.setText(entry.getName());

		TextView merchantOther = (TextView) convertView
				.findViewById(R.id.productQuantity);
		merchantOther.setText(String.valueOf(entry.getQuantity()));

		TextView totalPricer = (TextView) convertView
				.findViewById(R.id.productTotalPrice);
		totalPricer.setText(String.valueOf(entry.getQuantity()
				* entry.getPrice()));

		return convertView;
	}

	public void onClick(View view) {
		SalePojo entry = (SalePojo) view.getTag();
		getResulstList().remove(entry);
		// listPhonebook.remove(view.getId());
		notifyDataSetChanged();

	}

	private void showDialog(MerchantPojo entry) {
		// Create and show your dialog
		// Depending on the Dialogs button clicks delete it or do nothing
	}

}
